home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 51
/
Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso
/
-in_the_mag-
/
program_perfection
/
vbcc
/
mystartup
/
_main.c
next >
Wrap
C/C++ Source or Header
|
2000-02-16
|
1KB
|
80 lines
/*
* _main.c
*
* Startup stuff for VBCC
* Handles calling of constructors, destructors and atexit() functions
*
* Basically just pinched from vc.lib :)
*
* (C) Richard Drummond 1999
*
* Please feel free to use and abuse this code in your own
* programs, but don't blame me if it goes wrong . . .
*
* $Id: _main.c,v 1.2 1999/11/10 22:44:24 richard Exp $
* $Log: _main.c,v $
* Revision 1.2 1999/11/10 22:44:24 richard
* Update
*
* Revision 1.1.1.1 1999/11/10 22:38:28 richard
* Initial import to cvs
*
*/
#include <stddef.h>
#include <stdlib.h>
extern int main( char *, int );
extern __far void (*_ctors[])(), (*_dtors[])();
struct __exitfuncs *__firstexit;
void _exit( __reg("d0") int );
void
_main( char *command, int len )
{
void (**ctors)() = _ctors;
/* call constructors */
if( ctors++ )
while( *ctors ) (*ctors++)();
exit( main( command, len ) );
}
void exit( int returncode )
{
void (**dtors)() = _dtors;
int i;
struct __exitfuncs *p=__firstexit;
/* call atexit() functions */
while( p )
{
p->func();
p = p->next;
}
if( dtors )
{
/* goto end of destructor list */
for( i = 1; *dtors[i]; i++ )
;
/* call destructors in reverse */
while( --i )
(*dtors[i])();
}
_freemem();
_exit( returncode );
}